package com.hrpmar.service.impl;

import com.hrpmar.controller.vo.BingStais;
import com.hrpmar.controller.vo.DrugStatistics;
import com.hrpmar.controller.vo.Series;
import com.hrpmar.mapper.DrugstockMapper;
import com.hrpmar.mapper.DsdetailsMapper;
import com.hrpmar.mapper.OsdetailsMapper;
import com.hrpmar.mapper.PurdetailsMapper;
import com.hrpmar.service.StatisticsService;
import com.hrpmar.utils.RandomColor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by c on 2017-12-04.
 */
@Service()
@Transactional
public class StatisticsServiceImpl implements StatisticsService {

    @Resource
    private PurdetailsMapper purdetailsMapper;

    @Resource
    private DsdetailsMapper dsdetailsMapper;

    @Resource
    private OsdetailsMapper osdetailsMapper;

    @Resource
    private DrugstockMapper drugstockMapper;

    @Override
    public List<Series> searchDrugCountStas() {
        List<Series> seriesList = new ArrayList<Series>();
        //获取各种药品采购数量
        Series purSeries = new Series();
        purSeries.setType("column");
        purSeries.setName("采购总数量");
        List<DrugStatistics> list01 = purdetailsMapper.getDrugPurStas();
        List<Integer> list1 = new ArrayList<Integer>();
        for(DrugStatistics d1:list01){
            list1.add(d1.getTotalCount());
        }
        purSeries.setData(list1);
        seriesList.add(purSeries);
        //获取个种药品入库数量
        Series dsdSeries = new Series();
        dsdSeries.setType("column");
        dsdSeries.setName("入库总数量");
        List<DrugStatistics> list02 = dsdetailsMapper.getDrugDsdStas();
        List<Integer> list2 = new ArrayList<Integer>();
        for(DrugStatistics d2:list02){
            list2.add(d2.getTotalCount());
        }
        dsdSeries.setData(list2);
        seriesList.add(dsdSeries);
        //获取各种药品出库数量
        Series osdSeries = new Series();
        osdSeries.setType("column");
        osdSeries.setName("出库总数量");
        List<DrugStatistics> list03 = osdetailsMapper.getDrugOsdStas();
        List<Integer> list3 = new ArrayList<Integer>();
        for(DrugStatistics d3:list03){
            list3.add(d3.getTotalCount());
        }
        osdSeries.setData(list3);
        seriesList.add(osdSeries);
        //获取各种药品库存数量
        Series stoSeries = new Series();
        stoSeries.setType("spline");
        stoSeries.setName("现有库存");
        List<DrugStatistics> list04 = drugstockMapper.getDrugStoStas();
        List<Integer> list4 = new ArrayList<Integer>();
        for(DrugStatistics d4:list04){
            list4.add(d4.getTotalCount());
        }
        stoSeries.setData(list4);
        seriesList.add(stoSeries);

        //获取饼状图信息
        Series bingSeries = new Series();
        bingSeries.setType("pie");
        bingSeries.setName("药品库存总量");
        List<Integer> binList = new ArrayList<Integer>();
        binList.add(880);
        binList.add(75);
        bingSeries.setCenter(binList);
        bingSeries.setSize(140);
        bingSeries.getDataLabels().setEnabled(false);

        List<BingStais> bingList = new ArrayList<BingStais>();
        for(DrugStatistics d5:list04){
            BingStais b = new BingStais();
            b.setName(d5.getDrugType());
            b.setY(d5.getTotalCount());
            b.setColor(RandomColor.getRandomColor());
            bingList.add(b);
        }
        bingSeries.setData(bingList);
        seriesList.add(bingSeries);
        return seriesList;
    }
}
